package top.byfree.jbyan.saber.service

import cn.dev33.satoken.stp.StpInterface
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Component

/**
 * 权限认证
 *
 * @author jbyan
 * @since 21/3/2024
 */
@Component
class StpInterfaceImpl(
    @Autowired private val userService: UserService,
) : StpInterface {


    override fun getPermissionList(userId: Any?, loginType: String?): MutableList<String> {
        return (userId as? String)?.let { id ->
            userService.getPermList(id).map { it.permKey }.toMutableList()
        } ?: mutableListOf()
    }

    override fun getRoleList(userId: Any?, loginType: String?): MutableList<String> {
        return (userId as? String)?.let { id ->
            userService.getRoleList(id).map { it.roleKey }.toMutableList()
        } ?: mutableListOf()
    }
}